/*
	@Description: 获取本周起止日期
*/
export function getWeek(date) {
	var one_day = 86400000;
	var day = date.getDay();
	// 设置时间为当天的0点
	date.setHours(0);
	date.setMinutes(0);
	date.setSeconds(0);
	date.setMilliseconds(0);
	var week_start_time = date.getTime() - (day - 1) * one_day;
	var week_end_time = date.getTime() + (7 - day) * one_day;
	var last = week_start_time - 2*24*60*60*1000;
	var next = week_end_time + 24*60*60*1000;
	var month1 = new Date(week_start_time).getMonth()+1;
	var month2 = new Date(week_end_time).getMonth()+1;
	var day1 = new Date(week_start_time).getDate();
	var day2 = new Date(week_end_time).getDate();
	if(month1<10){
		month1 = "0"+month1;
	}
	if(month2<10){
		month2 = "0"+month2;
	}
	if(day1<10){
		day1 = "0"+day1;
	}
	if(day2<10){
		day2 = "0" + day2;
	}
	var time1 = month1+"-"+day1;
	var time2 = month2+"-"+day2;
	var map = new Map();
	map["stime"] = week_start_time; // 当前周周一零点的毫秒数
	map["etime"] = week_end_time; // 当前周周日零点的毫秒数
	map["stext"] = time1; // 当前周 周一的日期 mm.dd 如 03.14
	map["etext"] = time2; // 当前周 周日的日期 mm.dd 如 03.20
	map["last"] = last; // 上一周 周六零点的毫秒数
	map["next"] = next; // 下一周  周一零点的毫秒数
	map["text"] = time1+"至"+time2;
	return map;
}

/*
	@Description: 计算今天是本年第几周
*/
export function getWeekOrder() {
	let curDate = new Date();
	let  date = new Date();
	// 设置本年的第一天
	date.setMonth(0);
	date.setDate(1);
	let dateGap = curDate.getTime() - date.getTime();
	// 计算本年第几天
	// let day = Math.ceil(dateGap / 24*60*60*1000); //　输出天数， Math.ceil()向上取整
	let d = Math.round(dateGap / (24*60*60*1000))
	return Math.ceil((d + (date.getDay() + 1 - 1)) / 7);
}


/*
	@Description: 获取当月有几天
*/
export function getDaysInMon() {
	const today = new Date();
	const daysInMonth = new Date(today.getFullYear(), today.getMonth() + 1, 0).getDate();
	return daysInMonth
}
/*
	@Description: 获取周折线图横坐标
*/
export function getWeekXAxis(date) {
	const {stime} = getWeek(date)
	const arr = []
	for(let i=0;i<7;i++) {
		const timestmp = stime+ i * (24 * 60 * 60 * 1000);
		const date = new Date(timestmp)
		arr[i] = (date.getMonth()+1).toString().padStart(2,'0')+'-'+date.getDate().toString().padStart(2,'0')
	}
	return arr;
}